$(document).ready(function(){
	if($('#jqueryValidform')){jqCheckFormReady('jqueryValidform');}
});

function jqCheckFormReady(formObject,formSubmit)
{
	if($('#'+formObject+' .'+formSubmit))
	{
		$('#'+formObject+' .'+formSubmit).click(function(){return jqCheckForm($('#'+formObject));});
	}
	if($('#'+formObject+' .code'))
	{
		var e = $('#'+formObject+' .code');
		e.attr('src','/function/safecode.asp?rim='+Math.random());
		e.attr('alt','看不清楚，换一张');
		e.click(function(){$(this).attr('src','/function/safecode.asp?rim='+Math.random());});
	}
	$('#'+formObject).find("input").blur(function(){jqCheckFormList(this);});
	$('#'+formObject).submit(function(){return jqCheckForm($('#'+formObject));})
}


function jqCheckForm(formObject)
{
	formObject.data('reult',true);
	formObject.find("input").each(function(){
		if(jqCheckFormList(this)==false)
		{
			formObject.data('reult',false);
		}
	});
	return formObject.data('reult');
}


function jqCheckFormList(inputID)
{
	theReturn = true;
	if(theReturn==true && $(inputID).attr("checkNull")!=null){theReturn=checkNull(inputID);}//空
	if(theReturn==true && $(inputID).attr("checkLen")!=null){theReturn=checkLen(inputID);}//长度
	if(theReturn==true && $(inputID).attr("checkNum")!=null){theReturn=checkNum(inputID);}//数字
	if(theReturn==true && $(inputID).attr("checkInt")!=null){theReturn=checkInt(inputID);}//整数
	if(theReturn==true && $(inputID).attr("checkIntPlus")!=null){theReturn=checkIntPlus(inputID);}//正整数
	if(theReturn==true && $(inputID).attr("checkMobile")!=null){theReturn=checkMobile(inputID);}//手机
	if(theReturn==true && $(inputID).attr("checkEmail")!=null){theReturn=checkEmail(inputID);}//电子邮件
	if(theReturn==true && $(inputID).attr("checkCard")!=null){theReturn=checkCard(inputID);}//身份证
	if(theReturn==true && $(inputID).attr("checkDate")!=null){theReturn=checkDate(inputID);}//日期
	if(theReturn==true && $(inputID).attr("checkSame")!=null){theReturn=checkSame(inputID);}//与XX相同
	if(theReturn==true && $(inputID).attr("checkAccount")!=null){theReturn=checkAccount(inputID);}//帐号
	if(theReturn==true && $(inputID).attr("checkChineseName")!=null){theReturn=checkChineseName(inputID);}//中文名字
	return theReturn;

	function checkReturnWord(inputID,theWord)
	{
		var inputName = $(inputID).attr("name");
		if($("#"+inputName+"_inCheck")[0]==null){$("#formErrorShow").html(theWord);}
		else{
			if(theWord==""){theWord="√";}
			$("#"+inputName+"_inCheck").html(theWord);
			}
	}
	
	function checkNull(inputID)
	{
		var theCheckReturn=true;
		var re=/^\s{0,}$/;
		var theWord="";
		var inputName=$(inputID).attr("checkName")
		if(re.test($(inputID).val())){
			theWord="不能为空";
			theCheckReturn=false;
			if(inputName!=null){theWord=inputName+theWord;};
			}
		checkReturnWord(inputID,theWord);
		return theCheckReturn;
	}
		
		
	function checkLen(inputID)
	{
		var theCheckReturn=true;
		var theLen=$(inputID).attr("checkLen");
		var theLenMax=$(inputID).attr("checkLenMax");
		var theWord="";
		var inputName=$(inputID).attr("checkName");
		if($(inputID).val()!=""){
			if(theLen>0){
				if($(inputID).val().length<theLen){
				theWord="至少"+theLen+"个字符";
				if(inputName!=null){theWord=inputName+theWord;};
				theCheckReturn=false;
				}
			}
			if(theLenMax>0){
				if($(inputID).val().length>theLenMax){
				theWord="最多"+theLenMax+"个字符";
				if(inputName!=null){theWord=inputName+theWord;};
				theCheckReturn=false;
				}
			}
		}	
		checkReturnWord(inputID,theWord);
		return theCheckReturn;
	}
		
	
	function checkNum(inputID)
	{
		var theCheckReturn=true;
		var theWord="";
		var inputName=$(inputID).attr("checkName");
		if($(inputID).val()!=""){
			if(isNaN($(inputID).val())){
				theWord="输入无效";
				if(inputName!=null){theWord=inputName+theWord;};
				theCheckReturn=false;
				}
			}
		else{theWord="";}
		checkReturnWord(inputID,theWord);
		return theCheckReturn;
	}
		
		
	function checkInt(inputID)
	{
		var theCheckReturn=true;
		var re=/^-{0,1}\d+$/;
		var theWord="";
		var inputName=$(inputID).attr("checkName");
		if($(inputID).val()!=""){
			if(!re.test($(inputID).val())){
				theWord="输入无效";
				if(inputName!=null){theWord=inputName+theWord;};
				theCheckReturn=false;
				}
			}
		else{theWord="";}
		checkReturnWord(inputID,theWord);
		return theCheckReturn;
	}
		
		
	function checkIntPlus(inputID)
	{
		var theCheckReturn=true;
		var re=/^\d+$/;
		var theWord="";
		var inputName=$(inputID).attr("checkName");
		if($(inputID).val()!=""){
			if(!re.test($(inputID).val())){
				theWord="输入无效";
				if(inputName!=null){theWord=inputName+theWord;};
				theCheckReturn=false;
				}
			}
		else{theWord="";}
		checkReturnWord(inputID,theWord);
		return theCheckReturn;
	}
		
		
	function checkMobile(inputID)
	{
		var theCheckReturn=true;
		var re=/^0{0,1}13[0-9]{9}$/;
		var theWord="";
		var inputName=$(inputID).attr("checkName");
		if($(inputID).val()!=""){
			if(!re.test($(inputID).val())){
				theWord="输入无效";
				if(inputName!=null){theWord=inputName+theWord;};
				theCheckReturn=false;
				}
			}
		else{theWord="";}
		checkReturnWord(inputID,theWord);
		return theCheckReturn;
	}
		
		
	function checkEmail(inputID)
	{
		var theCheckReturn=true;
		var re=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
		var theWord="";
		var inputName=$(inputID).attr("checkName");
		if($(inputID).val()!=""){
				if(!re.test($(inputID).val())){
					theWord="输入无效";
					if(inputName!=null){theWord=inputName+theWord;};
					theCheckReturn=false;
					}
			}
		else{theWord="";}
		checkReturnWord(inputID,theWord);	
		return theCheckReturn;
	}
		
		
	function checkCard(inputID)
	{
		var theCheckReturn=true;
		var re=/^\d{14}(\d{1}|\d{4}|(\d{3}[xX]))$/;
		var theWord="";
		var inputName=$(inputID).attr("checkName");
		if($(inputID).val()!=""){
			if(!re.test($(inputID).val())){
				theWord="输入无效";
				if(inputName!=null){theWord=inputName+theWord;};
				theCheckReturn=false;
				}
			}	
		else{theWord="";}
		checkReturnWord(inputID,theWord);
		return theCheckReturn;
	}
		
		
	function checkDate(inputID)
	{
		var theCheckReturn=true;
		var re=/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
		var theWord="";
		var inputName=$(inputID).attr("checkName");
		if($(inputID).val()!=""){
			if(!re.test($(inputID).val())){
				theWord="输入无效";
				if(inputName!=null){theWord=inputName+theWord;};
				theCheckReturn=false;
				}
			}
		else{theWord="";}
		checkReturnWord(inputID,theWord);
		return theCheckReturn;
	}
		
		
	function checkSame(inputID)
	{
		var theCheckReturn=true;
		var theWord="";
		var inputName=$(inputID).attr("checkName");
		var theSameID=$(inputID).attr("checkSame");
		var theSameName=$(inputID).attr("checkSameName");
		if($(inputID).val()!=$("#"+theSameID).val()){
			theWord="应与"+theSameName+"内容相同";
			if(inputName!=null){theWord=inputName+theWord;};
			theCheckReturn=false;
			}
		checkReturnWord(inputID,theWord);
		return theCheckReturn;
	}
		
		
	function checkAccount(inputID)
	{
		var theCheckReturn=true;
		var re=/^[a-zA-Z]\w{5,19}$/;
		var theWord="";
		var inputName=$(inputID).attr("checkPwd");
		if($(inputID).val()!=""){
			if(!re.test($(inputID).val())){
				theWord="6-20位字母与数字的组合,并且用字母开头";
				if(inputName!=null){theWord=inputName+theWord;};
				theCheckReturn=false;
				}
			}
		else{theWord="";}
		checkReturnWord(inputID,theWord);
		return theCheckReturn;
	}
		
		
	function checkChineseName(inputID)
	{
		var theCheckReturn=true;
		var re=/^[\u4E00-\u9FA5]{2,10}$/;
		var theWord="";
		var inputName=$(inputID).attr("checkName");
		if($(inputID).val()!=""){
			if(!re.test($(inputID).val())){
				theWord="输入无效";
				if(inputName!=null){theWord=inputName+theWord;};
				theCheckReturn=false;
				}
			}
		else{theWord="";}
		checkReturnWord(inputID,theWord);
		return theCheckReturn;
	}
}